﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NS_QuangCaoTiepThiBUS;

namespace NS_QuangCaoTiepThi.QCTT.Admin
{
    public partial class DoiMatKhau : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnDoiMatKhau_Click(object sender, EventArgs e)
        {
            NguoiDung ndDTO = new NguoiDung();
            ndDTO.MaNguoiDung = (String)(Session["MaNguoiDung"]);
            ndDTO.MatKhau = (new Security()).MaHoaSHA1(txtMatKhauMoi.Text);

            if (txtMatKhauMoi.Text != string.Empty)
            {
                if (txtMatKhauMoiNhapLai.Text != string.Empty)
                {
                    if (txtMatKhauCu.Text != string.Empty)
                    {
                        if (txtMatKhauMoiNhapLai.Text == txtMatKhauMoi.Text)
                        {
                            NguoiDungBUS ndBUS = new NguoiDungBUS();
                            IList<NguoiDung> lstNguoiDung = ndBUS.LayThongTinNguoiDungTheoMaNguoiDung(ndDTO);
                            foreach (NguoiDung nd in lstNguoiDung)
                            {
                                string matKhauCu = (new Security()).MaHoaSHA1(txtMatKhauCu.Text);
                                if (matKhauCu == nd.MatKhau)
                                {
                                    ndBUS.DoiMatKhau(ndDTO);
                                }
                                else
                                {
                                    Alert.Show("Mat khau cu khong chinh xac");

                                    return;
                                }
                            }

                            Alert.Show("Da doi mat khau thanh cong");
                        }
                        else
                        {
                            Alert.Show("Mat khau khong chinh xac");

                            return;
                        }
                    }
                    else
                    {
                        Alert.Show("Mat khau cu khong duoc rong");

                        return;
                    }
                }
                else
                {
                    Alert.Show("Mat khau moi nhap lai khong duoc rong");

                    return;
                }
            }
            else
            {
                Alert.Show("Mat khau moi khong duoc rong");

                return;
            }
        }
    }
}